#include<iostream>
#include<string>
#include<stdio.h>

#include "ArgumentParser.h"
#include "Helper.h"
#include"Radar.h"

using namespace std;

Radar xRadar;
CArgumentParser* gpxArgumentParser = NULL;
std::string gsDirName = "./test";

int parseCommandLine(int argc, char**argv)
{
	gpxArgumentParser=new CArgumentParser("h");

	gpxArgumentParser->m_Helper->fillProgramName("nSapper");
	gpxArgumentParser->m_Helper->fillAuthor("sonofdelphi");
	gpxArgumentParser->m_Helper->fillSummary("Directory Scanner");
	gpxArgumentParser->m_Helper->fillUsageLine("[OPTIONS] <Directory>");
	gpxArgumentParser->fillHelpForOption('h',"Displays this help message");

	gpxArgumentParser->m_Helper->fillYear("2009");
	gpxArgumentParser->m_Helper->fillOwner("The Oraclique");
	gpxArgumentParser->m_Helper->fillTailMessage("Part of Neptuner Code-Management Suite.\nBuild:" __DATE__"/"__TIME__  "\nThis program comes with absolutely no warranty.");

	int nParseEndPos = gpxArgumentParser->parse(argc,argv);
	
	if(!gpxArgumentParser->wasParseSuccessful())
	{
		gpxArgumentParser->m_Helper->displayHelp();
		delete gpxArgumentParser;
		cerr<<"Invalid option supplied"<<endl;
		return -1;
	}

	return nParseEndPos+1;
}

int main(int argc, char** argv)
{
	int nProgArgIndex = parseCommandLine(argc, argv);
	if(nProgArgIndex<0)
	{
		return 1;
	}

	if(gpxArgumentParser->wasOptionSupplied('h'))
	{
		gpxArgumentParser->m_Helper->displayHelp();
		delete gpxArgumentParser;
		return 0;
	}

	if(nProgArgIndex<argc)
	{
		gsDirName=argv[nProgArgIndex];
	}
	else
	{
		cerr<<"Attempting to proceed with default: "<<gsDirName<<endl;
	}

	xRadar.scan(gsDirName);

	xRadar.dump();

	if(argc==1)
	{
		cerr<<"Press ENTER to continue..";
		getchar();
	}

	return 0;
}
